<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

/**
 *
 *
 *
 * @package     h
 * @subpackage  models
 * @category    models
 * @author      hyw
 * @copyright   copyright (c) 2012
 * @filesource
 */
class Appraisal_agencies_model extends Base_model {

    protected $_table_name = 'appraisal_agencies';
    protected $_key_name = 'appraisal_agencies_id';

    function get_info($id) {
        if (!empty($id))
            $where[$this->_key_name] = $id;
        $where['dtime'] = 0;
        return $this->fetch(NULL, $where, NULL, 'row');
    }

    function get_all() {
        $this->set_order_by('sequence,ASC');
        $where = array('dtime' => 0);
        return $this->fetch(NULL, $where);
    }

    function get_all_count() {
        $where = array('dtime' => 0);
        return $this->fetch(NULL, $where, NULL, "count");
    }

    function get_not_in($i) {

        $v = explode("/", $i);
        $this->db->where_not_in('value', array_map('trim', $v));
        $this->set_order_by('sequence,ASC');
        $where = array('dtime' => 0);
        return $this->fetch(NULL, $where);
    }

    function get_appraisal_agencies() {
        $this->set_order_by('sequence,ASC');
        $where = array('dtime' => 0);
        $result = $this->fetch(NULL, $where);
        $p = array();
        foreach ($result as $key => $val) {
            $p[$val->appraisal_agencies_id] = $val->value;
        }
        return $p;
    }

    function query_keyword($keyword = "", $limit) {
        if ($keyword != "")
            $this->set_or_like('value,explanation', $keyword);
        $this->set_limit($limit);
        $where = array('dtime' => 0);
        return $this->fetch(NULL, $where);
    }

    function query_keyword_count($keyword = null) {
        if ($keyword != "")
            $this->set_or_like('value,explanation', $keyword);
        $con["where"][] = array('dtime' => 0);
        $this->set_args_array($con);
        return $this->fetch_count();
    }

    function update_data($data) {
        $value = array('value' => $data['value'], 'explanation' => $data['explanation'], 'sequence' => $data['sequence'], 'mtime' => time());
        $where[] = array($this->_key_name => $data['id']);
        return $this->update($value, $where);
    }

    function add($data) {
        $data['ctime'] = time();
        return $this->insert($data);
    }

    function del($data) {
        $where[] = array($this->_key_name => $data['id']);
        $value = array('dtime' => time());
        return $this->update($value, $where);
    }

}
